package com.itheima.jingjie.TreeSet集合;

import java.util.Comparator;
import java.util.TreeSet;

public class TeacherTreeSet {
    public static void main(String[] args) {
        Comparator<Teacher> com = new Comparator<Teacher>() {
            @Override
            public int compare(Teacher o1, Teacher o2) {
                int result;
                //按总分排序
                result = o1.sum() - o2.sum() == 0 ? 0 : ((o1.sum() - o2.sum()) > 0 ? 1 : -1);
                //总分一样,按数学成绩排序
                result = result == 0 ? (o1.getMath() - o2.getMath() == 0 ? 0 : (o1.getMath() - o2.getMath() < 0 ? -1 : 1)) : result;
                //数学一样按语文成绩排序
                result = result == 0 ? (o1.getYuwen() - o2.getYuwen() == 0 ? 0 : (o1.getYuwen() - o2.getYuwen() < 0 ? -1 : 1)) : result;
                //语文成绩一样,按英语成绩排序
                //尚需成绩一样则英语成绩也一样
                result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
                return result;
            }
        };

        TreeSet<Teacher> set = new TreeSet<Teacher>(new Comparator<Teacher>() {
            @Override
            public int compare(Teacher o1, Teacher o2) {
                int x1, x2, x3, x4, x5;
                //按总分排序
                x1 = o1.sum() - o2.sum() == 0 ? 0 : ((o1.sum() - o2.sum()) > 0 ? 1 : -1);
                //总分一样,按数学成绩排序
                x2 = x1 == 0 ? (o1.getMath() - o2.getMath() == 0 ? 0 : (o1.getMath() - o2.getMath() < 0 ? -1 : 1)) : x1;
                //数学一样按语文成绩排序
                x3 = x2 == 0 ? (o1.getYuwen() - o2.getYuwen() == 0 ? 0 : (o1.getYuwen() - o2.getYuwen() < 0 ? -1 : 1)) : x2;
                //语文成绩一样,按英语成绩排序
                x4 = x3 == 0 ? (o1.getYyu() - o2.getYyu() == 0 ? 0 : (o1.getYyu() - o2.getYyu() < 0 ? -1 : 1)) : x3;
                //英语成绩一样按姓名排序
                x5 = x4 == 0 ? o1.getName().compareTo(o2.getName()) : x4;
                return x5;
            }
        });
        set.add(new Teacher("张三", 88, 87, 86));
        set.add(new Teacher("李四", 88, 87, 85));
        set.add(new Teacher("王五", 87, 87, 87));
        set.add(new Teacher("麻六", 87, 87, 87));
        set.add(new Teacher("苏七", 88, 87, 85));
        set.add(new Teacher("王八", 88, 87, 86));
        for (Teacher teacher : set) {
            System.out.print(teacher);
            System.out.println("总分是:    "+teacher.sum());
        }
    }
}
